package avicit.bdp.dms.das.rest;

import avicit.bdp.common.service.service.DataSourceService;
import avicit.platform6.core.exception.BusinessException;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@Api(tags = "消息推送REST接口")
@RequestMapping("/api/bdp/dms/subscribe")
public class PublishRest {

	@Autowired
	private DataSourceService dataSourceService;

	@ApiOperation(value = "发送消息")
	@ApiImplicitParam(name = "type", value = "类型", dataType = "String", paramType = "body", required = true)
	@PostMapping("/publishByType")
	public ResponseMsg<String> publishByType(@ApiIgnore @RequestBody Map map) {
		ResponseMsg<String> responseMsg = new ResponseMsg<>();
		String type = MapUtils.getString(map, "type");
		if (StringUtils.isBlank(type)) {
			throw new BusinessException("类型不能为空！");
		}
		dataSourceService.publishByType(type);
		return responseMsg;
	}
}
